#!/bin/bash
#定义变量
Project_Name=$1
Pid=$(ps aux | grep app.jar | grep -v grep | awk '{print $2}')
Time=$(date +%F_%T)
Dowload_URL=$(/data/ossutil64/ossutil64 -c /data/ossutil64/config sign oss://aw-k8s-nfs/$Project_Name/$Project_Name_$Time.hprof -e oss-cn-beijing.aliyuncs.com --timeout 300000000 | grep aliyuncs)

#打印堆栈
jmap -dump:format=b,file=/tmp/$Project_Name_$Time.hprof $Pid

#上传堆栈日志
/data/ossutil64/ossutil64 -c /data/ossutil64/config cp /tmp/$Project_Name_$Time.hprof oss://aw-k8s-nfs/$Project_Name/

#删除本地
rm -rf /tmp/$Project_Name_$Time.hprof

#输出下载 URL
printf "\n"
printf "dump 文件下载地址：\n"
echo ${Dowload_URL}
printf "\n"

#执行命令
#kubectl exec -n prd [pod名称] -- bash -c "/data/shell/Upload_jmap.sh [项目名称]"

#配置文件
[Credentials]
language=EN
accessKeyID=LTAI5t8fLteppgwsv1VeQc6R
accessKeySecret=tz9GbyvH1X20D6vHGSJo3Juz12iyve
endpoint=oss-cn-beijing-internal.aliyuncs.com